import { createStore, Store } from 'vuex'
import { InjectionKey } from 'vue'
import todos, { TodoState } from './modules/todos'

// 1.创建一个injectionKey
export const key: InjectionKey<Store<State>> = Symbol()


export type State = {
  counter: number,
  todos?: TodoState // 加上问号的原因是，如果不加在createStore中的state中会报错，会提示你需要添加一个todo的属性
}

export default createStore({
  state: {
    counter: 1
  },
  mutations: {
    add (state) {
      state.counter++
    }
  },
  modules: {
    todos
  }
})
